package com.ajie.bluetoothcard.ui;


import com.ajie.bluetoothcard.domain.Card;
import com.ajie.bluetoothcard.widget.CircularImage;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 名片详情
 * @author Jack
 *
 */
public class CardInfoActivity extends BaseActivity {
	private CircularImage cover_user_photo;
	private Card card;
	private ImageView sex_view;
	private TextView card_name,card_phone,card_age,card_address,card_time,card_introduction,card_type;
	private Bitmap avatatBitmap ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.card_info);
		super.onCreate(savedInstanceState);
		showTop(R.string.card_info, true);
		card = (Card) getIntent().getSerializableExtra("card");
		initView();
		initData();
	}
	private void initData() {
//		if(card!=null){
//			card_name.setText(card.getName());	
//			card_phone.setText(card.getPhone());	
//			card_age.setText(card.getAge());	
//			card_address.setText(card.getAddress());	
//			card_time.setText(card.getTime());	
//			card_introduction.setText(card.getIntroduction());
//			if("1".equals(card.getSex())){
//				sex_view.setImageResource(R.drawable.info_sex_men);
//			}else{
//				sex_view.setImageResource(R.drawable.info_sex_women);
//			}
//			if("1".equals(card.getType())){
//				card_type.setText(R.string.rich);	
//			}else{
//				card_type.setText(R.string.poor);	
//			}
//			if(!"".equals(card.getAvatar())){
//				avatatBitmap = BitmapFactory.decodeFile(card.getAvatar());
//				if(avatatBitmap!=null){
//					cover_user_photo.setImageBitmap(avatatBitmap);
//				}else{
//					showToast("头像丢失");
//				}
//			}
//		}
	}
	@Override
	protected void initView() {
		// TODO Auto-generated method stub
		super.initView();
		btn_next.setVisibility(View.VISIBLE);
		top_title_right.setVisibility(View.GONE);
		right_icon.setVisibility(View.VISIBLE);
		cover_user_photo = (CircularImage) findViewById(R.id.cover_user_photo);
		cover_user_photo.setImageResource(R.drawable.avatar_profile);

		sex_view = (ImageView) findViewById(R.id.sex_view);
		card_name = (TextView) findViewById(R.id.card_name);
		card_phone = (TextView) findViewById(R.id.card_phone);
		card_type = (TextView) findViewById(R.id.card_type);
		card_age = (TextView) findViewById(R.id.card_age);
		card_address = (TextView) findViewById(R.id.card_address);
		card_time = (TextView) findViewById(R.id.card_time);
		card_introduction = (TextView) findViewById(R.id.card_introduction);
	}
	
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);
		switch (v.getId()) {
		case R.id.btn_next:
			startActivityForResult((new Intent(this,CardInfoEditActivity.class).putExtra("card",card).putExtra("type","edit")),10002);
			break;

		default:
			break;
		}
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode == 10002 && resultCode == 20001){
			card = (Card) data.getSerializableExtra("card");
			initData();
		}
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if(avatatBitmap!=null){
			avatatBitmap.recycle();
		}
	}
}
